#include<sys/socket.h>
#include<netinet/in.h>
#include <netdb.h>
#include<pthread.h>

#define PORT 3000

//User information
 struct UserInfo
 {
	 char name[128];
	 char ip_address[128];
	 int state;
 };

//user send login information
 struct login_info
 {
	 char name[128];
	 char password[128];
 };

struct UserInfo UserList[1024];

 int socket_descriptor;
 int clientfd;

struct sockaddr_in sin; 


void initServer();
void *preocess_Login_Thread();

int main(int argc,char ** argv)
{
  
  //init server
   struct sockaddr_in remote_addr;
   pthread_t login_thread;
   int res;
   int sin_size;
   sin_size=sizeof(struct sockaddr_in);

   initServer();

   while(1){
     
	 
     if( (clientfd=accept(socket_descriptor,(struct sockaddr *)&remote_addr,&sin_size))==-1){
	 
	   perror("accept error");

	   continue;
	 
	 }

     else{
	         
	      res=pthread_create(&login_thread,NULL,preocess_Login_Thread,NULL);
	      
	 
	 }
   
   
   }
   
}

//init Server
void initServer()
{
   
   socket_descriptor=socket(AF_INET,SOCK_STREAM,0);
   sin.sin_family = AF_INET; 
   sin.sin_port=htons(PORT);
   sin.sin_addr.s_addr=INADDR_ANY;
   bind(socket_descriptor,(struct socketaddr *)&sin, sizeof(struct sockaddr_in) );
   listen(socket_descriptor,1024);

}

void *preocess_Login_Thread()
{

    while(1){
	 
	  struct login_info user_login; 
	  recv(clientfd, &user_login,sizeof(user_login),0);


                

	}
       



}

